﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace System.Collections.Generic
{
    [Serializable]    
    [ComVisible(false)]
    [DebuggerDisplay("Count = {Count}")]
    internal class ReadOnly<T> : IList<T>, ICollection<T>, IEnumerable<T>, IList, ICollection, IEnumerable
    {
        private IList<T> innerList;

        public ReadOnly()
            :this(null)
        {           
        }

        public ReadOnly(IList<T> innerList)
        {
            this.innerList = innerList ?? new List<T>();
        }

        public int IndexOf(T item)
        {
            return innerList.IndexOf(item);
        }

        public void Insert(int index, T item)
        {
            
        }

        public void RemoveAt(int index)
        {
            
        }

        public T this[int index]
        {
            get
            {
                return innerList[index];
            }
            set
            {
                
            }
        }

        public void Add(T item)
        {
            
        }

        public void Clear()
        {
            
        }

        public bool Contains(T item)
        {
            return innerList.Contains(item);
        }

        public void CopyTo(T[] array, int arrayIndex)
        {
            innerList.CopyTo(array, arrayIndex);
        }

        public int Count
        {
            get { return innerList.Count; }
        }

        public bool IsReadOnly
        {
            get { return true; }
        }

        public bool Remove(T item)
        {
            return false;
        }

        public IEnumerator<T> GetEnumerator()
        {
            return innerList.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return innerList.GetEnumerator();
        }

        public int Add(object value)
        {
            return -1;
        }

        public bool Contains(object value)
        {
            return Contains((T)value);
        }

        public int IndexOf(object value)
        {
            return IndexOf((T)value);
        }

        public void Insert(int index, object value)
        {
            
        }

        public bool IsFixedSize
        {
            get { return true; }
        }

        public void Remove(object value)
        {
            
        }        

        public void CopyTo(Array array, int index)
        {
            using (var en = innerList.GetEnumerator())
            for (int i = index; i < array.Length && en.MoveNext(); i++)
                array.SetValue(en.Current, i);            
        }

        public bool IsSynchronized
        {
            get { return false; }
        }

        public object SyncRoot
        {
            get { return this; }
        }


        object IList.this[int index]
        {
            get
            {
                return innerList[index];
            }
            set
            {
                
            }
        }
    }
}
